// pages/orderform/orderform.js
const app = getApp()
import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
Page({
  onFocus() {
    wx.navigateTo({
        url: '/pages/Ssearch/Ssearch',
      })
  },
  onClickShow() {
    this.setData({ show: true });
  },
  onClickHide() {
    this.setData({ show: false });
  },
  onClickShow2() {
    this.setData({ show2: true });
  },
  onClickHide2() {
    this.setData({ show2: false });
  },
  onClickShow3() {
    this.setData({ show3: true });
  },
  onClickHide3() {
    this.setData({ show3: false });
  },
  onClickShow4() {
    this.setData({ show4: true });
  },
  onClickHide4() {
    this.setData({ show4: false });
  },
  onClickShow6() {
    this.setData({ show6: true });
  },
  onClickHide6() {
    this.setData({ show6: false });
  },
  pay(e) {
    // console.log(e.currentTarget.dataset.id)
    Dialog.confirm({
        title: '订单支付',
        message: '是否支付此订单?',
      })
        .then(() => {
          // on confirm
        const value = wx.getStorageSync('token');
    let that = this;
    wx:wx.request({
      url:  app.globalData.baseurl+'/orderForm/updateUserOrderStatus',
      method: 'POST',
      data: {
        orderId: e.currentTarget.dataset.id,
        statusId: 6,
        sid: 8,
      },
      header: {
        'content-type': 'application/json', // 默认值
        'Authorization':value,
      },
      success(res){
        console.log(res);
      }
    })
        })
        .catch(() => {
          // on cancel
        });
},
pay(e) {
  // console.log(e.currentTarget.dataset.id)
  Dialog.confirm({
      title: '确认支付此订单',
    })
      .then(() => {
        // on confirm
  const value = wx.getStorageSync('token');
  let that = this;
  wx:wx.request({
    url:  app.globalData.baseurl+'/orderForm/updateUserOrderStatus',
    method: 'POST',
    data: {
      orderId: e.currentTarget.dataset.id,
      statusId: 6,
      sid: 8,
    },
    header: {
      'content-type': 'application/json', // 默认值
      'Authorization':value,
    },
    success(res){
      console.log(res),
      wx.showToast({
        title: "支付成功！",
        icon: 'none',
        duration: 2000
      })
    }
  })
      })
      .catch(() => {
        // on cancel
      });
},
mess(e){
  console.log(e.currentTarget.dataset.id)
  wx.navigateTo({
    url: '/pages/mess/mess?id='+e.currentTarget.dataset.id,
  })
},
    /**
     * 页面的初始数据
     */
    data: {
        active: 0,//默认选中
        show: false,
        show3: false,
        show2: false,
        show4: false,
        show6: false,
        orderInfo: [],
        reserve: [],
        ing:[],
        pay:[],
        mess:[],
        notmess:[]
    },
    getUserInfo(event) {
      console.log(event.detail);
    },
  
    onClose() {
      this.setData({ show: false });
    },
      showPopup() {
        this.setData({ show: true });
      },
    
      onClose() {
        this.setData({ show: false });
      },
        noop() {},
    
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
    const value = wx.getStorageSync('token');
      let that = this;
      //待审核
      wx:wx.request({
        url: app.globalData.baseurl+'/orderForm/selectUserCheckOrderForm',
        method: 'get',
        header: {
          'content-type': "application/json",
          'Authorization':value,
        },
        success(res){
          console.log(res)
          that.setData({
            orderInfo: res.data.data
          })
        }
      })
      //待接收
      wx:wx.request({
        url: app.globalData.baseurl+'/orderForm/selectUserReserveOrderForm',
        method: 'get',
        header: {
          'content-type': "application/json",
          'Authorization':value,
        },
        success(res){
          console.log(res)
          that.setData({
            reserve: res.data.data
          })
        }
      })
      //进行中
      wx:wx.request({
        url: app.globalData.baseurl+'/orderForm/selectUserIngOrderForm',
        method: 'get',
        header: {
          'content-type': "application/json",
          'Authorization':value,
        },
        success(res){
          console.log(res)
          that.setData({
            ing: res.data.data
          })
        }
      })
      //待支付
      wx:wx.request({
        url: app.globalData.baseurl+'/orderForm/selectUserPayOrderForm',
        method: 'get',
        header: {
          'content-type': "application/json",
          'Authorization':value,
        },
        success(res){
          console.log(res)
          that.setData({
            pay: res.data.data
          })
        }
      })
      //未评价
      wx:wx.request({
        url: app.globalData.baseurl+'/orderForm/selectUserCommentingOrderForm',
        method: 'get',
        header: {
          'content-type': "application/json",
          'Authorization':value,
        },
        success(res){
          console.log(res)
          that.setData({
            notmess: res.data.data
          })
        }
      })
      //已评价
      wx:wx.request({
        url: app.globalData.baseurl+'/orderForm/selectUserCommentedOrderForm',
        method: 'get',
        header: {
          'content-type': "application/json",
          'Authorization':value,
        },
        success(res){
          console.log(res)
          that.setData({
            mess: res.data.data
          })
        }
      })
        Dialog.confirm({
            title: '确认支付此订单',
          })
            .then(() => {
              // on confirm
            })
            .catch(() => {
              // on cancel
            });
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})